import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
from io import StringIO

mpl.rcParams['pdf.fonttype'] = 42
mpl.rcParams['ps.fonttype'] = 42
mpl.rcParams['axes.linewidth'] = 1.5
mpl.rcParams['lines.linewidth'] = 3
mpl.rcParams['lines.markersize'] = 10
mpl.rcParams['font.size'] = 15
mpl.rcParams['xtick.labelsize'] = 14
mpl.rcParams['ytick.labelsize'] = 16
mpl.rcParams['legend.fontsize'] = 14
mpl.rcParams['legend.framealpha'] = 0
mpl.rcParams['legend.borderpad'] = 0.1
mpl.rcParams["axes.labelweight"] = "bold"
mpl.rcParams["axes.labelsize"] = 14
mpl.rcParams['font.family'] = 'sans-serif'
mpl.rcParams['figure.figsize'] = (7, 3.5)
mpl.rc('font', family='SimHei', weight='bold')
# mpl.rc("font",family='MicroSoft YaHei',weight="bold")

csv = '''Stage,System,Time
计算原子覆写,APKeep*,2.35
计算原子覆写,Flash (PUM),0.62
计算原子覆写,Flash,0.61
原子覆写聚合,APKeep*,0
原子覆写聚合,Flash (PUM),0.03
原子覆写聚合,Flash,0.42
数据平面模型更新,APKeep*,4.55
数据平面模型更新,Flash (PUM),4.84
数据平面模型更新,Flash,0.37
'''

df = pd.read_csv(StringIO(csv), sep=",")

def plot():
  ax = sns.barplot(x = 'Stage',
              y = 'Time',
              hue = 'System',
              data = df)
  for i in ax.containers:
    ax.bar_label(i,)
  plt.ylabel('Time (s)', fontdict={'family': 'sans-serif'})
  plt.xlabel(None)
  plt.ylim(0,5.5)
  plt.legend().set_title(None)
  # plt.yscale('log')
  plt.tight_layout(pad=0.1)
  plt.savefig('./figures/model/i2-teardown.pdf')
  # Show the plot
  plt.show()
  
plot()